package com.xueyi.system;

import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestController {
    @Resource
    private Redisson redisson;

    @GetMapping("/redisson")
    public void list(String key, Long expire) throws Exception {
        RLock lock = redisson.getLock(key);
        lock.tryLock();
        RBucket bucket = redisson.getBucket(key);
        if (expire != null) {
            bucket.set(expire);
            System.out.println(bucket.get());
        }
    }
}
